<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="Content-type" content="text/html; charset=utf-8">
		<link href="css/add.css" rel="stylesheet" type="text/css" />
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="css/style.css">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
		<script type="text/javascript" src="js/jquery-3.3.1.min.js" ></script>
		<script type="text/javascript" src="js/submit.js"></script>
		<script type="text/javascript" src="js/popups.js"></script>
		<script type="text/javascript">
			var ip;
			var surveyId,id;
			var mycars=new Array();
			$(function(){
				var configJson='js/confing.json'
				$.getJSON(configJson,function(data){
					ip=data.urlip;
					setSize();
       				addEventListener('resize',setSize);
       				scrollDiv () 
       				var thisURL = document.URL;
					var getval =thisURL.split('?')[1];
					if(getval)
					{
						var showVal= getval.split("=")[1]; 
						id=showVal;
						surveyId="surveyId="+showVal;
					}
					else{
						surveyId="surveyId=0";
					}
					identi();
					from();
					getlist();
					for(var i=0;i<count-2;i++){
						checkid[i]=-1;
					}
				});
            });
            function setSize() {
            	document.documentElement.style.fontSize = document.documentElement.clientWidth/750*100+'px';
            }
			var link={"党办校办": "http://dbxb.zjgsu.edu.cn/",
					"宣传部":"http://tzb.zjgsu.edu.cn/tzb/",  
					"统战部":" http://tzb.zjgsu.edu.cn/tzb/",
					"科研部":" http://kyc.zjgsu.edu.cn/default.html",
					"人事处":" http://rsc.zjgsu.edu.cn/",
					"资产处":" http://sbc.zjgsu.edu.cn/",
					"工会":" http://jgzj.zjgsu.edu.cn/",
					"杂志社 ":"http://zzs.zjgsu.edu.cn/CN/volumn/home.shtml",
					"档案馆":" http://zhdas.zjgsu.edu.cn/",
					"采购中心":" http://cgzx.zjgsu.edu.cn/",
					"学生处":"  http://xsc.zjgsu.edu.cn/",
					"保卫处":" http://bwc.zjgsu.edu.cn/",
					"团委":" http://youth.zjgsu.edu.cn/",
					"图书馆":" http://lib.zjgsu.edu.cn/",
					"网络中心":" http://nic.zjgsu.edu.cn/",
					"后勤中心":" http://hq.zjgsu.edu.cn/",
					"体工部":" http://tgb.zjgsu.edu.cn/",
					"国教学院":" http://sie.zjgsu.edu.cn/",
					"研究生院":" http://yjs.zjgsu.edu.cn/",
					"教务处":" http://jww.zjgsu.edu.cn/",
					"计财处":"  http://cwc.zjgsu.edu.cn/",
					"国际处":"  http://international.zjsu.edu.cn/",
					"招就处":" http://zhaoban.zjgsu.edu.cn/",
					"公共事务处":" http://zwc.zjgsu.edu.cn/",
					"浙商博物馆" :"http://www.zsbwg.org/",
					"创业学院" :"http://znq.zjgsu.edu.cn/"};
			var type=-1;
			function identi()
			{
				$.ajax({
     				type: "get",
   					url: ip+"/user/type",
  					data:{
  						
  					},
    				dataType: "json",
     				xhrFields: {withCredentials: true},
    				crossDomain:true,
    				success: function(res) {
    					console.log("sssss")
    					console.log(res)
						if(res.code==0)
						{
							type=res.data;//0是老师，1是学生
							//$("#welcomTex").append("<button id='yes_btn' style='font-size: .35rem;position: absolute ;top:15%;right: 2%;background: none;border: none;' >退出</button>");
						}
    				},
    				async:false
     			});
			}
			function go(str){
				window.location.href="login.html";
			}
			function from() {				 
				$.ajax({
					type: "get",
					url:ip+"/client?"+surveyId,
					data: {
					},
					async: true,
					dataType: "json",
					xhrFields: {withCredentials: true},
      				crossDomain:true,
					success: function(res) {
						console.log(res)
						if(res.msg)
						{
							if(res.data){
								    
									jqalert({
										title: '提示',
										content: '该问卷为实名问卷，您需要登录才可查看相关信息',
									});	
								    $(".fd-btn").remove();
									surveyId=res.data.surveyId;
									setTimeout('go(surveyId)',1000);

							}
							else{
								var myurl="situation2.html?msg="+res.msg+"?sid="+id;
								window.location.assign(encodeURI(myurl));
							}
						}
						else{
								document.getElementById("title").innerHTML=res.data.title;
								if(res.data.section!="未设置部门"){
								var href="<a style='text-decoration: underline;color:rgb(80, 169, 189);text;display: block;font-size:.3rem;margin-top:2%' href='"+link[res.data.section]+"'>"+"部门官网 ：  "+res.data.section+"</a>"
								$("#title").append(href)}
								text=res.data.xmlStr;
								parseXML(text);
						}
					},
					Error: function() {
						alert("服务器出错");
					},
					async:false
				});
			}
			
			//以下使用的是jquery框架，简单易学
			//解析xml
			function parseXML(text) {
				//后端获取到的xml
				//text = "<?xml version=\"1.0\"?><h:html xmlns=\"http://www.w3.org/2002/xforms\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:h=\"http://www.w3.org/1999/xhtml\" xmlns:jr=\"http://openrosa.org/javarosa\" xmlns:odk=\"http://www.opendatakit.org/xforms\" xmlns:orx=\"http://openrosa.org/xforms\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><h:head><h:title>questionnaire</h:title><model><instance><questionnaire id=\"questionnaire\"><title/><basic_information><store_name/><store_gps/><collegeType/><sex/><job/></basic_information><survey_question><familiar/><attitude/><right_rate/><efficiency/><overall_evaluation/><advice/></survey_question><meta><instanceID/></meta></questionnaire></instance><bind nodeset=\"/questionnaire/title\" readonly=\"true()\" type=\"string\"/><bind nodeset=\"/questionnaire/basic_information/store_name\" required=\"true()\" type=\"string\"/><bind nodeset=\"/questionnaire/basic_information/store_gps\" required=\"true()\" type=\"geopoint\"/><bind nodeset=\"/questionnaire/basic_information/collegeType\" required=\"true()\" type=\"select1\"/><bind nodeset=\"/questionnaire/basic_information/sex\" type=\"select1\"/><bind nodeset=\"/questionnaire/basic_information/job\" required=\"true()\" type=\"select1\"/><bind nodeset=\"/questionnaire/survey_question/familiar\" required=\"true()\" type=\"select1\"/><bind nodeset=\"/questionnaire/survey_question/attitude\" required=\"true()\" type=\"select1\"/><bind nodeset=\"/questionnaire/survey_question/right_rate\" required=\"true()\" type=\"select1\"/><bind nodeset=\"/questionnaire/survey_question/efficiency\" required=\"true()\" type=\"select1\"/><bind nodeset=\"/questionnaire/survey_question/overall_evaluation\" required=\"true()\" type=\"select1\"/><bind nodeset=\"/questionnaire/survey_question/advice\" type=\"string\"/><bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/questionnaire/meta/instanceID\" readonly=\"true()\" type=\"string\"/></model></h:head><h:body><input ref=\"/questionnaire/title\"><label>欢迎使用本系统！</label></input><group ref=\"/questionnaire/basic_information\"><label>基本信息</label><input ref=\"/questionnaire/basic_information/store_name\"><label>what's your name</label></input><input ref=\"/questionnaire/basic_information/store_gps\"><label>collect the GPS</label></input><select1 ref=\"/questionnaire/basic_information/collegeType\"><label>您所在的学院类型？</label><item><label>A.经管类</label><value>economy</value></item><item><label>B.理工类</label><value>science</value></item><item><label>C.文法类</label><value>grammar</value></item></select1><select1 ref=\"/questionnaire/basic_information/sex\"><label>您的性别是？</label><item><label>男</label><value>male</value></item><item><label>女</label><value>female</value></item></select1><select1 ref=\"/questionnaire/basic_information/job\"><label>您的职称？</label><item><label>初级</label><value>primary</value></item><item><label>中级</label><value>middle</value></item><item><label>高级</label><value>high</value></item></select1></group><group ref=\"/questionnaire/survey_question\"><label>调查问题</label><select1 ref=\"/questionnaire/survey_question/familiar\"><label>对该部门的熟悉程度？</label><item><label>熟悉</label><value>familiar_very</value></item><item><label>一般</label><value>familiar_ordinary</value></item><item><label>不熟悉</label><value>familiar_not</value></item></select1><select1 ref=\"/questionnaire/survey_question/attitude\"><label>该部门的服务态度？</label><item><label>非常满意</label><value>attitude_very</value></item><item><label>满意</label><value>attitude_good</value></item><item><label>基本满意</label><value>attitude_oridinary</value></item><item><label>不满意</label><value>attitude_not</value></item><item><label>很不满意</label><value>attitude_verynot</value></item></select1><input ref=\"/questionnaire/survey_question/advice\"><label>你对该部门工作提出的建议</label></input></group></h:body></h:html>";
				//根据不同浏览器解析xml
				try //Internet Explorer
				{
					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async = "false";
					xmlDoc.loadXML(text);
				} catch(e) {
					try //Firefox, Mozilla, Opera, etc.
					{
						parser = new DOMParser();
						xmlDoc = parser.parseFromString(text, "text/xml");
					} catch(e) {
						alert(e.message);
						return;
					}
				}
				/*head=xmlDoc.getElementsByTagName("h:head")[0].getElementsByTagName("model")[0].getElementsByTagName("bind");
				content = xmlDoc.getElementsByTagName("h:body")[0].getElementsByTagName("group");   //获取问卷内容*/
				var node=xmlDoc.documentElement.childNodes;
				for(var i=0;i<node.length;i++)
				{
					if(node[i].nodeName=="h:head"){
						head=node[i];
					}
					if(node[i].nodeName=="h:body")
					{
						content=node[i];
					}
				}
				//生成问卷内容
				var contentInfo = "";
				
				for(var y=0;y<content.childNodes.length;y++)
				{
					if(content.childNodes[y].nodeName=="group"){
					x = content.childNodes[y].childNodes;
				//遍历问卷内容content的所有子节点
				//每个子节点是一道问题
					for(i = 0; i < x.length;i++) {
						if(x[i].childNodes.length!=0){
							nodeType = x[i].nodeName;
							nodeContent = x[i];
							//将节点名称和节点内容传入buildQues生成问题
							//再将返回的每个问题的html字符串连接起来
							contentInfo = contentInfo + buildupQues(nodeType, nodeContent);
						}
						
					}
					$("#ques-content").html(contentInfo);
					$(".submits").html("<a id='tipe' style='text-align: center;'><input type='button' style='text-decoration: none; line-height: .3rem;'  class='submit2' value='提交' onclick='shclick()'></a>");
					
					}
				}
			}

			//全局变量
			//问题编号计数器
			var count =1;
			var qui=0;
			//生成问题
			function buildupQues(type, node) {
				var info="";
				var flag=reques(node);
				if(flag!=2){
				//根据节点名称生成不同的副题目或问题
				switch(type) {
					case 'label':
						info = buildSubheader(node.childNodes[0].nodeValue);
						break;
					case 'select1':
						info = buildSingle(node);//题目
						count++;
						break;
					case 'input':
						info = buildInput(node);
						count++;
						break;
					default:
						break;
					}
				}
				return info;
			}

			//生成副标题
			function buildSubheader(data) {
				return "<h3 id='ques-subhead' class='lagtitle'>" + data + "</h3>"
			}
			
			//生成单选题
			var talg=0;
			function buildSingle(node) {
				//生成题目的前、后部分
				var front = "<div class='block full"+count+"'>",
					end = "</div>";
				//生成总选项的前、后部分
				var	quesItem = "",
					endItem = "</div>";
				var x = node.childNodes;
				//遍历一个问题的子节点
				var flag=0;
				for(var j = 0; j < x.length;j++) { 
					if(x[j].childNodes.length!=0){
						flag++;
						var flag1=reques(node);
					//第一个子节点为题目
						if(flag == 1) {
							if(flag1==1){
								var quesTitle = "<div class='question"+count+" res' id='question"+count+"' style='margin: 3% 0 4% -5%' value='1'>"+"<span style='color: red;'>*</span>"+" "+count + "." + node.childNodes[j].childNodes[0].nodeValue + "</div>";
							}
							else if(flag1==0){
								var quesTitle = "<div class='question"+count+" res' id='question"+count+"'>"+count + "." + node.childNodes[j].childNodes[0].nodeValue + "</div>";
							}
						} 
					//剩余子节点为单选题选项
						else {
							if(flag1==2){
								continue;
							}else{
							var data;
							/*var data = node.childNodes[j].getElementsByTagName("label")[0].childNodes[0].nodeValue;*/
							for(var s=0;s<x[j].childNodes.length;s++)
							{
								if(x[j].childNodes[s].nodeName=="label"){
								data=x[j].childNodes[s].childNodes[0].nodeValue;
								}
							}
							var frontItem = "<div class='radio "+talg+"'>";
							var item = "<label class='cssradios cssradios-primary' for='" +talg + "' name=' "+count+"'><input type='radio' class='questionradio'  onchange='test(this.id,this.name)' id='" + talg + "' name='example"+count+"'  "+"value='" + data + "'>"+data+ "</label>";
							talg++;
							quesItem = quesItem + frontItem + item + endItem;
							}
						}
					}
					
					}
					ques = front + quesTitle + quesItem + end;
				 
				//返回时生成的html字符串
				return ques;
			}
			var checkid=new Array();
			var checkname;
			function test(id,name){
				console.log(id)
				var sh=parseInt(name[7])-1;
				if(checkid[sh]!=id){
					var strg3="."+checkid[sh];
					console.log(strg3+"remove")
					$(strg3).removeClass("change")
					var strg='.'+id;
					console.log(strg+"add")
					$(strg).addClass("change")
					checkid[sh]=id;
					checkname=name;
				}
			}
			
			//生成填空题
			function buildInput(node) {
				//生成题目的前、后部分
				var front = "<div class='block full"+count+"'>",
					end = "</div>";
				var quesTitle;
				//生成总选项的前、后部分
				for(var j=0;j<node.childNodes.length;j++){
					if(node.childNodes[j].childNodes.length!=0)
					{
						var flag=reques(node);
						if(flag==1){
							quesTitle = "<div class='question"+count+" res' id='question"+count+"' style='margin: 3% 0 0 -5%'  value='1'>" +"<span style='color: red;'>*</span>"+" "+count + "." + node.childNodes[j].childNodes[0].nodeValue + "</div>";
						}else if(flag==0){
							quesTitle = "<div class='question"+count+" res' id='question"+count+"'>"+count + "." + node.childNodes[j].childNodes[0].nodeValue + "</div>";
						}
					}
				}
				var item = "<textarea type='text' id='example-input' name='example"+count+"'  class='form-control'></textarea>";
				var ques = front + quesTitle+ item + end;
				//返回时生成的html字符串
				return ques;
			}
			function reques(node2){
				var flag=1;
				var nodehead=head.childNodes[3];
				for(var i=0;i<nodehead.childNodes.length;i++)
				{
					if(nodehead.childNodes[i].nodeName=="bind"){
						var str=nodehead.childNodes[i].getAttribute("nodeset");
						if(nodehead.childNodes[i].getAttribute("nodeset")==node2.getAttribute("ref")){
							if(type!=-1){
								if((str.search("job"))!=-1&&type==1){//判断是否是学生
									flag=2;
									break;
								}
								if(((str.search("familiar"))!=-1||(str.search("grade"))!=-1)&&type==0){//判断是否是老师
									if(str.search("familiar")!=-1){
											mycars[qui]=count+qui; 
									}
									flag=2;
									break;
								}
							}
							if(nodehead.childNodes[i].getAttribute("required")!="true()")
							{
								flag=0;
								break;
							}
						}
					}
				}
				return flag;
			}
		function scrollDiv () {
		var ie6 = document.all; 
		var dv = $('#title'), st; 
		dv.attr('otop', dv.offset().top); //存储原来的距离顶部的距离 
		$(window).scroll(function () { 
		st = Math.max(document.body.scrollTop || document.documentElement.scrollTop); 
		if (st > parseInt(dv.attr('otop'))) { 
			if (ie6) {//IE6不支持fixed属性，所以只能靠设置position为absolute和top实现此效果 
				dv.css({ position: 'absolute', top: st,'background':'white'}); 
			}else if (dv.css('position') != 'fixed'){
				dv.css({ 'position': 'fixed', top: 0 ,'background':'rgb(254, 255, 223)'});
			}
		} else if(dv.css('position') != 'static') {
			dv.css({ 'position': 'static','background':'white'});
		}
		}); 
	}
		var nextid=0;
		var total;
		function getlist(){
       			$.ajax({
						type:"get",
						url:ip+"/client/surveyName",
						data:{
							
						},
						async:true,
						dataType: "json",
						xhrFields: {withCredentials: true},
      					crossDomain:true,
      					success:function(res)
      					{
      						if(!res.code){
      							if(typeof res.data=='string')
      							{
      								
      							}else{
      								total=res.data.total;
      								if(res.data.survey[0].id==id)
      								{
      									total=total-1;
      									if(total){
      									nextid=res.data.survey[1].id;
      									}
      								}else{
      									nextid=res.data.survey[0].id;
      								}
      								if(total){
      								$(".submits").html("<a id='tipe' style='text-align: center;'><input type='button' style='text-decoration: none; line-height: .3rem;'  class='submit2' value='提交并填写下一份问卷' onclick='shclick()'></a>");
      							}
      							}
      						}
      					}
      			});
       		}

		</script>
	</head>
	<body style="background: rgb(248,248,248);">
		
		<div>
			<div>
			<div onClick="javascript :window.location.href='list.html'" style="font-size: .3rem;background:rgb(172, 230, 243);line-height: .6rem;"><a style="margin: 0 0 0 3%; ">首页</a></div>
			<h4 id="title" style="text-align: center;background: white;width: 100%;margin: 0 auto 2%; padding: 1% 0;z-index:999;font-size: .37rem;"></h4>
			</div>
			<div style="margin: 3% auto 0">
				<div id="ques-content" style="background:white;padding: 3% 5% 2%;border: 1px dashed #dae0e8;">
				</div>
				<div class="submits" >
				</div>
			<div style="text-align: center;text-decoration: none;margin: 2% auto 10%;"><a style="text-decoration: none;font-size: .32rem;" href="https://wj.qq.com/s/2953793/5f86/">有问题点击这里告诉我们</a></div>
	
			</div>
		</div>
	</body>
</html>
